package cn.itcast.controller;

import cn.itcast.service.user.UserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: zhaojie
 * @Date: Created in 13:14 2018/8/9
 * @Description: 登录验证
 */
@Controller
public class LoginController {
    @Autowired
    @Qualifier("loginServiceImpl")
    private UserLoginService userLoginService;

    /**
     * 1.通过访问localhost:7900/ 会首先跳转到login.html
     * 2.登陆验证成功后跳转到home.html
     * 3.home.html 中包含了注销操作，
     * 4.<form th:action="@{/logout}" method="post">表示进行注销行为
     * 5.spring security自动进行注销成功后 在WebSecurityConfig 中进行配置logoutSuccessUrl("/my/index") 跳转到该controller
     * 6.controller进行业务操作并返回
     * @return
     */
    @RequestMapping("/")
    public String Login(){
        return "home";
    }

    @RequestMapping("/getAll")
    @ResponseBody
    public String getAll(){
        return "所有信息";
    }

    /**
     * @return 注销成功后跳转的页面
     */
    @RequestMapping("/my/index")
    public String logoutSuccess(){
        return "login";
    }

    //没有作用
//    @RequestMapping("/loginIn")
//    @ResponseBody
//    public String LoginIn(HttpServletRequest request){
//        String username= request.getParameter("username");
//        String password = request.getParameter("password");
//        int i = userLoginService.checkUserInfo(username, password);
//        return i>0?"登录成功":"登录失败";
//    }
}
